package com.mg.framework.kernel;

import java.io.IOException;
import java.io.InputStream;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Assets {

	public static Bitmap logo = null;
	public static Bitmap start = null;
	public static Bitmap exit = null;
	
	public static Bitmap gBg = null;
	public static Bitmap[] clouds = null;
	
	public static Bitmap moveC = null;
	public static Bitmap okC = null;
	public static Bitmap cancelC = null;
	public static Bitmap menuC = null;
	
	
	
	private static MG mg = null;
	private static AssetManager assetManager = null;

	static void initAssets(MG mg) {
		Assets.mg = mg;
		Assets.assetManager = mg.getAssets();
	}

	static void loadingInitAssets() {
		Assets.logo = Assets.loadingAssets("Glogo.png");
		
		Assets.gBg = Assets.loadingAssets("gbg.png");
		Assets.clouds = new Bitmap[4];
		Assets.clouds[0] = Assets.loadingAssets("y1.png");
		Assets.clouds[1] = Assets.loadingAssets("y2.png");
		Assets.clouds[2] = Assets.loadingAssets("y3.png");
		Assets.clouds[3] = Assets.loadingAssets("y4.png");
		
		Assets.moveC = Assets.loadingAssets("MoveC.png");
		Assets.okC = Assets.loadingAssets("OkC.png");
		Assets.cancelC = Assets.loadingAssets("CancelC.png");
		Assets.menuC = Assets.loadingAssets("MenuC.png");
	}

	public static void loadingMenuAssets() {
		Assets.start = Assets.loadingAssets("start.png");
		Assets.exit = Assets.loadingAssets("exit.png");
	}

	private static Bitmap loadingAssets(String fileName) {
		Bitmap bitmap = null;
		try {
			InputStream in = assetManager.open(fileName);
			bitmap = BitmapFactory.decodeStream(in).copy(
					Bitmap.Config.ARGB_8888, true);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bitmap;
	}

	private static Bitmap[] loadingAssets(String[] fileName) {
		Bitmap[] bitmaps = new Bitmap[fileName.length];
		try {
			for (int i = 0; i < fileName.length; i++) {
				InputStream in = assetManager.open(fileName[i]);
				bitmaps[i] = BitmapFactory.decodeStream(in).copy(
						Bitmap.Config.ARGB_8888, true);
				in.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bitmaps;
	}

	public static MG getMG() {
		return Assets.mg;
	}
}